#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed May  4 16:27:52 2022

@author: cythnia
"""
#导入工具包
import pandas as pd
import numpy as np
#传入数据
data=pd.read_excel('/Users/cythnia/Desktop/徐梦苏.xlsx')
data.head()
#营业收入进行滚动相加
df1 = data.loc[:,'营业收入2008':'营业收入2021'].rolling(3,axis=1).sum()
df1
#营业总收入进行滚动相加
df2 = data.loc[:,'营业总收入2008':'营业总收入2021'].rolling(3,axis=1).sum()
#写入同一个excel中不同sheet
write=pd.ExcelWriter('/Users/cythnia/Desktop/徐萌酥.xlsx',engine='xlsxwriter')
df1.to_excel(write,index=False,sheet_name='营业收入')
df2.to_excel(write,index=False,sheet_name='营业总收入')
write.save()#重要一步，不然没有数据